class Solution {
public:
    int lengthOfLongestSubstring(string s) 
    {
        int i = 0, j = 0;
        int length = 0, result = 0;
        int size = s.size();

        if(size <= 1) 
            return size;

        while(j < size)
        {
            char c = s[j];

            for(int index = i; index < j; index++)
            {
                if(c == s[index])
                {
                    i = index + 1;
                    length = j - i;
                    break;
                }
            }

            j++;
            length++;
            result = max(length, result);
        }

        return result;
    }
};